<?php
	class Log
	{
		private static $ErrorLog = Array();
		private static $_fileName = "ErrorLog.txt";
		
		// Get the message and add it to the array.
		public static function LogMessage($errorMessage)
		{
			Log::$ErrorLog[] = $errorMessage;
		}
		
		// Create a Error and add it to both the array and a textfile.
		public static function LogError($message, $errorMessage)
		{			
			// Add the message to the array.
			Log::$ErrorLog[] = $message = '<font color="red">' . $message . '</font>';
			
			// Save the error to a logfile.
			Log::SaveError($errorMessage);
		}
		
		// Return the error filled array.
		public static function GetErrorArray()
		{			
			return Log::$ErrorLog;	
		}
		
		// Return the current time in the Y-m-d H:i:s format.
		private static function SetTime()
		{
			$dateTime = date("Y-m-d H:i:s", time());
			
			return $dateTime;
		}
		
		// Save the error messages to a file.
		private static function SaveError($errorMessage)
		{
			// Format the error, add timestame and ip.
			$errorMessage = Log::SetTime() . " : " . $_SERVER['REMOTE_ADDR'] . " : " . $errorMessage;
			// Write it to the file.
			$handle = fopen(Log::$_fileName, "a");
			fwrite($handle, $errorMessage."\r\n");
			fclose($handle);
		}
		
		// Return array with all the errors from the errorlog.
		public static function GetErrorsFromFile()
		{
			$temp = Array();
			
			$handle = fopen(Log::$_fileName, "r");
			
			while(!feof($handle))
			{
				$temp[] = fgets($handle);
			}
			
			fclose($handle);
			
			return $temp;	
		}
	}	